How can I bind a custom color to WPF toolkit ColorPicker? [on hold]
Posted
by
tube-builder
on Programmers
See other posts from Programmers
or by tube-builder
Published on 2013-06-28T07:37:22Z
Indexed on
2013/06/28
10:28 UTC
Read the original article
Hit count: 346
I need to bind the SelectedColor property of ColorPicker to a custom color which is not present in available colors. I created a simple test to show my problem. My xaml:
<xctk:ColorPicker SelectedColor="{Binding Path=Test}"></xctk:ColorPicker>
Code behind (CurrentStyle.PenColor returns an integer value which equals 13109765
):
public Color Test
{
get;
set;
}
public MyClass()
{
DataContext = this;
Test = Color.FromArgb((byte)((CurrentStyle.PenColor >> 24) & 0xFF),
(byte)((CurrentStyle.PenColor >> 16) & 0xFF),
(byte)((CurrentStyle.PenColor >> 8) & 0xFF),
(byte)(CurrentStyle.PenColor & 0xFF));
InitializeComponent();
}
And that's how my ColorPicker looks like when the window is loaded (I don't have enough rep to post images so it's just links):
http://s22.postimg.org/frzh2fgy9/image.png
Though, when I go to Advanced colors I can see that the color has been recognized and set correctly. Here is a pic:
http://s13.postimg.org/gjv4cmy07/image.png
Hope for your help. Thanks a lot!
EDIT
I implemented INotifyPropertyChanged, still to no avail. Here's the code:
public Color Test
{
get
{
return test;
}
set
{
if (test != value)
{
test = value;
OnPropertyChanged("Test");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string prop)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(prop));
}
Maybe I'm doing smth wrong here.
© Programmers or respective owner